<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/webchat.js"></script>
</head>
<body>

<script>
    var i=0;
     function WebSocketTest()
         {
            if ("WebSocket" in window)
            {
               //alert("您的浏览器支持 WebSocket!");

               // 打开一个 web socket
               //var ws = new WebSocket("ws://localhost:8081/echo");
               var ws = new WebSocket("ws://localhost:8083/roomws/1d331/t");

               ws.onopen = function()
               {
                  // Web Socket 已连接上，使用 send() 方法发送数据
                  ws.send("发送数据"+i);
                  i++;
                  for(var j=0;j<10;j++){
                    ws.send("发送数据"+i);
                    i++;
                  }
                  alert("数据发送中...");
               };

               ws.onmessage = function (evt)
               {
                  var received_msg = evt.data;
                  alert("数据已接收..."+received_msg);
                  // ws.send("发送数据2"+i);
               };

               ws.onclose = function()
               {
                  // 关闭 websocket
                  alert("连接已关闭...");
               };
            }

            else
            {
               // 浏览器不支持 WebSocket
               alert("您的浏览器不支持 WebSocket!");
            }
         }
         WebSocketTest();
</script>
</body>
</html>